package com.wandian.news.mvvm.lifetool;

import android.os.Bundle;
import android.view.View;

import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.GridLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.alibaba.android.arouter.launcher.ARouter;
import com.chad.library.adapter.base.BaseQuickAdapter;
import com.mylib.libcore.config.RouterConfig;
import com.mylib.libcore.mvvm.BaseMVVMActivity;
import com.mylib.libcore.tools.CSJADTools;
import com.mylib.libcore.tools.GDTADTools;
import com.mylib.libcore.utils.ActivityUtil;
import com.mylib.libcore.utils.UIUtils;
import com.wandian.news.R;
import com.wandian.news.adapter.LifeToolRecycleAdapter;
import com.wandian.news.databinding.NewsActivityKnowledgeBinding;
import com.wandian.news.databinding.NewsActivityLifeToolBinding;

import java.util.ArrayList;
import java.util.List;

import static com.mylib.libcore.config.AppConfig.CSJ_BANNER_ONE_ID;
import static com.mylib.libcore.config.AppConfig.CSJ_BANNER_TWO_ID;
import static com.mylib.libcore.config.AppConfig.GDT_APP_MB_PIC_TWO;

/**
 * @author Administrator
 * @date 2019/12/18-14:28
 * @description 生活工具activity
 **/
@Route(path = RouterConfig.ROUTER_ACTIVITY_NEWS_LIFE_TOOL)
public class LifeToolActivity extends BaseMVVMActivity<LifeToolActivityViewModel> {
    private NewsActivityLifeToolBinding dataBinding;
    private LifeToolRecycleAdapter lifeToolRecycleAdapter;

    @Override
    public void init(Bundle savedInstanceState) {
        dataBinding = DataBindingUtil.setContentView(this, R.layout.news_activity_life_tool);
        dataBinding.setLifecycleOwner(this);
        dataBinding.setViewModel(mViewModel);
        initViewData();
        initClink();
        initRecycle();
        mViewModel.getDataJQ();
        mViewModel.getDataXTS();
    }

    private void initViewData(){
        ActivityUtil.getInstance().showStatusView(this,dataBinding.viewSysTop,true);
        dataBinding.bindTransparentToolBar.toolBarTvTitle.setText("生活百科");
        mViewModel.textJQ.observe(this,text->{
            if(!UIUtils.isEmpty(text))dataBinding.tvLifeJq.setText(text+"");
        });
        mViewModel.textXTS.observe(this,text->{
            if(!UIUtils.isEmpty(text))dataBinding.tvLifeXts.setText(text+"");
        });
        //获取广告
        CSJADTools.loadCSJAdMiddleBanner(getContext(),dataBinding.rlAdBottom,"",CSJ_BANNER_TWO_ID,375,120);
        GDTADTools.loadHFAdByID(getContext(),dataBinding.flAdBottom,GDT_APP_MB_PIC_TWO,375,0 );
    }

    private void initClink(){
        dataBinding.bindTransparentToolBar.toolBarIvBack.setOnClickListener(v -> {
            finish();
        });
    }

    private void initRecycle(){
        lifeToolRecycleAdapter = new LifeToolRecycleAdapter(R.layout.news_item_life_tool_style);
        RecyclerView.LayoutManager layoutManager = new GridLayoutManager(this,3);
        dataBinding.recycler.setLayoutManager(layoutManager);
        dataBinding.recycler.setAdapter(lifeToolRecycleAdapter);
        List<String> listTitle = new ArrayList<>();
        listTitle.add("菜谱宝典");
        listTitle.add("食材成分");
        listTitle.add("体质查询");
        listTitle.add("中药大全");
        listTitle.add("药物说明");
        listTitle.add("生日性格");
        listTitle.add("星座运势");
        listTitle.add("黄历查询");
    //    listTitle.add("周公解梦");
        lifeToolRecycleAdapter.setNewData(listTitle);
        lifeToolRecycleAdapter.setOnItemClickListener(new BaseQuickAdapter.OnItemClickListener() {
            @Override
            public void onItemClick(BaseQuickAdapter baseQuickAdapter, View view, int i) {
                String menu = baseQuickAdapter.getData().get(i).toString();
                switch (menu){
                    case "菜谱宝典":
                        ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_MENU).navigation();
                        break;
                    case "食材成分":
                        ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_FOOD).navigation();
                        break;
                    case "体质查询":
                        ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_BODY).navigation();
                        break;
                    case "中药大全":
                        ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_MEDICINE).withString("title","中药大全").navigation();
                        break;
                    case "药物说明":
                        ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_MEDICINE).withString("title","药物说明").navigation();
                        break;
                    case "生日性格":
                        ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_BIRTH_DAY).navigation();
                        break;
                    case "星座运势":
                        ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_CONSTELLATION).navigation();
                        break;
                    case "黄历查询":
                        ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_NL).navigation();
                        break;
                    case "周公解梦":
                        ARouter.getInstance().build(RouterConfig.ROUTER_ACTIVITY_NEWS_ZGJM).navigation();
                        break;
                }
            }
        });
    }

}
